package com.czx.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class DelayedConfig {

    public static final String YOUR_EXCHANGE_NAME = "delayed-exchange";
    public static final String YOUR_QUEUE_NAME = "delayed-queue";
    public static final String YOUR_ROUTING_KEY = "delayed-key";

    @Bean // 创建了一个交换机
    public CustomExchange delayedExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        CustomExchange customExchange = new CustomExchange(YOUR_EXCHANGE_NAME, "x-delayed-message",
                true, false, args);
        return customExchange;
    }

    @Bean
    public Queue delayedQueue() {
        return new Queue(YOUR_QUEUE_NAME);
    }

    @Bean
    public Binding delayedBinding() {
        return BindingBuilder.bind(delayedQueue()).to(delayedExchange()).with(YOUR_ROUTING_KEY).noargs();
    }

}